import generator
import alg
import time
import numpy as np
import random
import string
import numpy as np
import matplotlib.pyplot as plt
def runtime(func,data):
    start=time.perf_counter()
    func(data)
    end=time.perf_counter()
    return end-start
def runtime2(func,data,k):
    start=time.perf_counter()
    func(data,k)
    end=time.perf_counter()
    return end-start
#测试接雨水
a=generator.generator(num = 1, length = 10, begin = 0, step = 50,choice = 0)
b=generator.generator(num = 1, length = 100, begin = 0, step = 50,choice = 0)
c=generator.generator(num = 1, length = 1000, begin = 0, step = 50,choice = 0)
d=generator.generator(num = 1, length = 10000, begin = 0, step = 50,choice = 0)
x=np.array([runtime(alg.trap,a),runtime(alg.trap,b),runtime(alg.trap,c),runtime(alg.trap,d)])
plt.figure()
plt.plot([10,100,1000,10000],x)

#三角形最短路径和测试
a1=generator.generator(num = 1, length = 10, begin = 0, step = 50,choice = 1)
b1=generator.generator(num = 3, length = 10, begin = 0, step = 50,choice = 1)
c1=generator.generator(num = 6, length = 10, begin = 0, step = 50,choice = 1)
d1=generator.generator(num = 9, length = 10, begin = 0, step = 50,choice = 1)
x1=np.array([runtime(alg.minimumTotal,a1),runtime(alg.minimumTotal,b1),runtime(alg.minimumTotal,c1),runtime(alg.minimumTotal,d1)])
plt.figure()
plt.plot([1,3,6,9],x1)

#不同路径测试
m,n=6,7
m1,n1=10,14
m2,n2=13,20
m3,n3=18,24
x2=np.array([runtime2(alg.uniquePaths,m,n),runtime2(alg.uniquePaths,m1,n1),runtime2(alg.uniquePaths,m2,n2),runtime2(alg.uniquePaths,m3,n3)])
plt.figure()
plt.plot([6,10,13,18],x2)

#编辑距离测试
a2=generator.strr(4,3)
b2=generator.strr(20,26)
c2=generator.strr(50,68)
d2=generator.strr(80,79)
x3=np.array([runtime2(alg.minDistance,a2[0],a2[1]),runtime2(alg.minDistance,b2[0],b2[1]),runtime2(alg.minDistance,c2[0],c2[1]),runtime2(alg.minDistance,d2[0],d2[1])])

plt.figure()
plt.plot([4,20,50,80],x3)

#正则表达式测试
x4=np.array([runtime2(alg.isMatch,a2[0],a2[1]),runtime2(alg.isMatch,b2[0],b2[1]),runtime2(alg.isMatch,c2[0],c2[1]),runtime2(alg.isMatch,d2[0],d2[1])])
plt.figure()
plt.plot([4,20,50,80],x4)
plt.show()










# Listtime1=[]
# Listtime2=[]
# Listtime3=[]
# Listtime4=[]
# Listdata=[]#总数据集
# Listdata.append(Listtime1)
# Listdata.append(Listtime2)
# Listdata.append(Listtime3)
# Listdata.append(Listtime4)
# for i in range(4):
#     Listdata[i].append(a[i])
#     Listdata[i].append(b[i])
#     Listdata[i].append(c[i])
#     Listdata[i].append(d[i])
# List1=[]
# List2=[]
# List3=[]
# List4=[]
# List5=[]#定义五个列表存放五个算法运行时间
# for i in range(4):
#     List1.append(runtime(alg.reversePairs,Listdata[0][i]))
#     List2.append(runtime(alg.reversePairsn, Listdata[1][i]))
#     List3.append(runtime(alg.majorityElement, Listdata[2][i]))
#     List4.append(runtime2(alg.findKthLargest, Listdata[3][i],2))
# print(List1)
# print(List2)
# print(List3)
# print(List4)


# 接雨水需要生成数组
# 正则表达式需要生成两个字符串
# 不同路径需要连个不同的数
# 编辑距离要连个字符串
# 三角需要列表
